﻿using D.B.Data.API.Applications.Command.RoleMenusCommand;
using D.B.Data.Domain.DTO.Output;
using D.B.Data.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;


namespace D.B.Data.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleMenusController : ControllerBase
    {

        private readonly IMediator mediator;

        public RoleMenusController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RoleTreeDTO>>> GetRole([FromQuery]GetRoleCommand command)
        {
            return mediator.Send(command);
        }


        /// <summary>
        /// 查菜单 树形
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MenuTreeDTO>>> GetMenus([FromQuery]MenusCommand command)
        {
            return mediator.Send(command);
        }


        /// <summary>
        /// 分配角色菜单
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddRoleMenus(AddRoleMenusCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 角色id 查菜单Id
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<long>>> RoleIdGetMenusid([FromQuery]RoleIdGetMenusListCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RoleIdMenusDTO>>> Menus([FromQuery]UserRoleMenusCommand command)
        {
            return mediator.Send(command);
        }
    }
}
